package com.example;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.impl.VisualServiceImpl;

import java.util.ArrayList;
import java.util.List;


public class HuoshanSdkImagChange {

    public static void main(String[] args) {
        IVisualService visualService = VisualServiceImpl.getInstance();
        // call below method if you dont set ak and sk in ～/.vcloud/config
        visualService.setAccessKey("AKLTOGVlN2UzZDQ3MjQ1NDFiNmExNDc4MDRmYjEyMTVlMzM");
        visualService.setSecretKey("WWpVNE1EazRZV1ZoTjJZME5EZzJZVGcxWldabU5qTXhaR0kyWmpneU9XRQ==");

        List<String > strings = new ArrayList<>();
        strings.add("https://images.daojia.com/jz/pic/3919c04b4bb828923c23ac5daa34b659.jpeg");
        for (String url :strings){
            RequestObject requestObject = new RequestObject();
            requestObject.setReqKey("dressing_diffusionV2");
            RequestObject.GarmentDTO garmentDTO= new RequestObject.GarmentDTO();
            List<RequestObject.GarmentDTO.DataDTO> list = new ArrayList<>();
            list.add(new RequestObject.GarmentDTO.DataDTO("upper","https://images.daojia.com/jz/pic/c68a21c08b89e926bd28c50a49262700.JPG"));
            garmentDTO.setData(list);
            requestObject.setGarment(garmentDTO);
            RequestObject.ModelDTO modelDTO = new RequestObject.ModelDTO();

            modelDTO.setUrl(url);
            requestObject.setModel(modelDTO);


            try {
                Object response = visualService.cvSubmitTask(requestObject);
                System.out.println(JSON.toJSONString(response));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    public static class RequestObject{

        @JSONField(name = "req_key")
        private String reqKey;
        @JSONField(name = "model")
        private ModelDTO model;
        @JSONField(name = "garment")
        private GarmentDTO garment;

        public String getReqKey() {
            return reqKey;
        }

        public RequestObject setReqKey(String reqKey) {
            this.reqKey = reqKey;
            return this;
        }

        public ModelDTO getModel() {
            return model;
        }

        public RequestObject setModel(ModelDTO model) {
            this.model = model;
            return this;
        }

        public GarmentDTO getGarment() {
            return garment;
        }

        public RequestObject setGarment(GarmentDTO garment) {
            this.garment = garment;
            return this;
        }

        public static class ModelDTO {
            @JSONField(name = "url")
            private String url;

            public String getUrl() {
                return url;
            }

            public void setUrl(String url) {
                this.url = url;
            }
        }

        public static class GarmentDTO {
            @JSONField(name = "data")
            private List<DataDTO> data;

            public List<DataDTO> getData() {
                return data;
            }

            public void setData(List<DataDTO> data) {
                this.data = data;
            }

            public static class DataDTO {
                @JSONField(name = "type")
                private String type;
                @JSONField(name = "url")
                private String url;

                public DataDTO(String type, String url) {
                    this.type = type;
                    this.url = url;
                }

                public String getType() {
                    return type;
                }

                public void setType(String type) {
                    this.type = type;
                }

                public String getUrl() {
                    return url;
                }

                public void setUrl(String url) {
                    this.url = url;
                }
            }
        }
    }
}
